package com.mika.music.mapper;

import com.mika.music.model.Comment;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface CommentMapper {

    @Insert("insert into comment(user_id, music_id, message) values(#{userId}, #{musicId}, #{message})")
    Integer addComment(Comment comment);

    @Select("select c.*, u.user_name , m.title as musicName from `comment` as c, `user` as u , music as m where c.user_id = u.id and c.music_id = #{musicId} and c.music_id = m.id order by c.create_time desc limit #{commentsPerPage} offset #{startIndex}")
    List<Comment> getComments(Integer musicId, Integer startIndex, Integer commentsPerPage);


    @Select("select count(*) from comment where music_id = #{musicId}")
    Integer getCommentCountsByMusicId(Integer musicId);

    @Delete("delete from comment where music_id = #{musicId}")
    Integer deleteCommentByMusicId(Integer musicId);
}
